


**************************************************
*                  MAIN TABLES                   *
**************************************************


*** T 1 - Example of question, scoring grid and anonymized answer

			
			 
*** T 2 - MGMT on Surplus - Cross Section
set more off
use "Carreri_JOP_Cross.dta", clear
cap erase "Table2_Panelfullsample.tex"
cap erase "Table2_Panelfullsample.txt"
foreach y in surplus_w {
* column 1 - baseline (year and region FE)
reg `y' mgmt i.year i.region_id pia ///
		, cl(municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard = r(sd)*_b[mgmt]
	outreg2 using "Table2_Panelfullsample.tex", tex(land) keep(mgmt)  /// 
	addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
	nocon label bdec(3) adec(3)
* column 2 - baseline + mayor controls 
reg `y' mgmt  i.year i.region_id pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		, cl(municipality_id) 
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard = r(sd)*_b[mgmt]
	outreg2 using "Table2_Panelfullsample.tex", tex(land) keep(mgmt)  /// 
	addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
	nocon label bdec(3) adec(3)
* column 3 - baseline + mayor controls + mayor party FE
reg `y' mgmt  i.year i.region_id i.party_id pia  ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		, cl(municipality_id) 
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard = r(sd)*_b[mgmt]
	outreg2 using "Table2_Panelfullsample.tex", tex(land) keep(mgmt)  /// 
	addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
	nocon label bdec(3) adec(3)
* column 4 - baseline + mayor controls + mayor party FE + year_of_term FE
reg `y' mgmt  i.year i.region_id i.party_id i.year_of_term pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		, cl(municipality_id) 
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard = r(sd)*_b[mgmt]
	outreg2 using "Table2_Panelfullsample.tex", tex(land) keep(mgmt)  /// 
	addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
	nocon label bdec(3) adec(3)
		
* South/North/Centre if area=="`x'"
foreach x in south north centre {
cap erase "Table2_Panel`x'.tex"
cap erase "Table2_Panel`x'.txt"
* column 1 - baseline (year and region FE)
reg `y' mgmt i.year i.region_id pia ///
		if area=="`x'" , cl(municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard = r(sd)*_b[mgmt]
	outreg2 using "Table2_Panel`x'.tex", tex(land) keep(mgmt)  /// 
	addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
	nocon label bdec(3) adec(3)
* column 2 - baseline + mayor controls
reg `y' mgmt i.year i.region_id pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		if area=="`x'" , cl(municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard = r(sd)*_b[mgmt]
	outreg2 using "Table2_Panel`x'.tex", tex(land) keep(mgmt) /// 
	addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
	nocon label bdec(3) adec(3)
* column 3 - baseline + mayor controls + mayor party FE
reg `y' mgmt i.year i.region_id i.party_id pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		if area=="`x'" , cl(municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard = r(sd)*_b[mgmt]
		outreg2 using "Table2_Panel`x'.tex", tex(land) keep(mgmt)  /// 
	addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
	nocon label bdec(3) adec(3)
* column 4 - baseline + mayor controls + mayor party FE + year_of_term FE
reg `y' mgmt i.year i.region_id i.party_id i.year_of_term pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		if area=="`x'" , cl(municipality_id)	
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard = r(sd)*_b[mgmt]
		outreg2 using "Table2_Panel`x'.tex", tex(land) keep(mgmt)  /// 
	addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
	nocon label bdec(3) adec(3)
erase "Table2_Panel`x'.txt"
}
erase "Table2_Panelfullsample.txt"
}
			 
			 

*** T 3 - No difference in levels: MGMT on Surplus in Pre-period
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "Table3.tex"
cap erase "Table3.txt"
keep if year_normalized==-1|year_normalized==-2|year_normalized==-3|year_normalized==-4
forvalues i=1(1)4 {
 gen d`i'=mgmt*period_`i'
 label var d`i' "Mean Competence Score x year -`i'"
 }
areg surplus_w d1-d4 , ///
 vce(cluster municipality_id) absorb(year_normalized)
	su surplus_w if e(sample)==1
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	outreg2 using "Table3.tex",  bdec(3) adec(3) nocon label /// 
		addstat(Municipalities, `num_mun', SD Surplus, `msurplus_w') ///
		ctitle("Surplus, Full Sample") replace
areg surplus_w d1-d4 if area=="south", ///
 vce(cluster municipality_id) absorb(year_normalized)
	su surplus_w if e(sample)==1
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	outreg2 using "Table3.tex",  bdec(3) adec(3) nocon label ///
		addstat(Municipalities, `num_mun', SD Surplus, `msurplus_w') ///
		ctitle("Surplus, South") 
areg surplus_w d1-d4 if area=="north", ///
 vce(cluster municipality_id) absorb(year_normalized)
	su surplus_w if e(sample)==1
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	outreg2 using "Table3.tex",  bdec(3) adec(3) nocon label ///
		addstat(Municipalities, `num_mun', SD Surplus, `msurplus_w') ///
		ctitle("Surplus, North") 
areg surplus_w d1-d4 if area=="centre", ///
 vce(cluster municipality_id) absorb(year_normalized)
	su surplus_w if e(sample)==1
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	outreg2 using "Table3.tex",  bdec(3) adec(3) nocon label ///
		addstat(Municipalities, `num_mun', SD Surplus, `msurplus_w') ///
		ctitle("Surplus, Centre") 
erase "Table3.txt"	 

			 
			 
*** T 4 - MGMT on Surplus - Diff-in-Diff
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "Table4_Panelfullsample.txt"
cap erase "Table4_Panelfullsample.tex"
* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "Table4_Panelfullsample.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 2 - baseline + region FE
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "Table4_Panelfullsample.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w' , Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label		
* column 3 - baseline + region FE + mayor controls
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "Table4_Panelfullsample.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w' , Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "Table4_Panelfullsample.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w' , Standardized Effect, `standard') ///
		bdec(3) adec(3) dec(3) nocon label			
erase "Table4_Panelfullsample.txt"
foreach x in south north centre {
cap erase "Table4_Panel`x'.txt"
cap erase "Table4_Panel`x'.tex"
* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe surplus_w post_mgmt if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "Table4_Panel`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w' , Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 2 - baseline + region FE
reghdfe surplus_w post_mgmt if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "Table4_Panel`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w' , Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 3 - baseline + region FE + mayor controls
reghdfe surplus_w post_mgmt if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "Table4_Panel`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w' , Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe surplus_w post_mgmt if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "Table4_Panel`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w' , Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label			
erase "Table4_Panel`x'.txt"
}
	
	
	
*** T 5 - MGMT and previous mayor's covariates
use "Carreri_JOP_Cross.dta", clear
duplicates drop municipality_id, force
cap erase "Table5_PanelA.txt"
cap erase "Table5_PanelA.tex"
cap erase "Table5_PanelB.txt"
cap erase "Table5_PanelB.tex"
keep if area=="south"
* Panel A
reg ageold mgmt
outreg2 using "Table5_PanelA.tex", tex(land) bdec(3) nocon label	
reg job_highold mgmt
outreg2 using "Table5_PanelA.tex", tex(land) bdec(3) nocon label	
reg job_lowold mgmt
outreg2 using "Table5_PanelA.tex", tex(land) bdec(3) nocon label	
reg job_unemployedold mgmt
outreg2 using "Table5_PanelA.tex", tex(land) bdec(3) nocon label	
reg educ_less_13old mgmt
outreg2 using "Table5_PanelA.tex", tex(land) bdec(3) nocon label	
reg educ_13old mgmt
outreg2 using "Table5_PanelA.tex", tex(land) bdec(3) nocon label	
reg educ_14_18old mgmt
outreg2 using "Table5_PanelA.tex", tex(land) bdec(3) nocon label	
* Panel B
reg ageold age
outreg2 using "Table5_PanelB.tex", tex(land) bdec(3) nocon label	
reg job_highold job_high
outreg2 using "Table5_PanelB.tex", tex(land) bdec(3) nocon label	
reg job_lowold job_low
outreg2 using "Table5_PanelB.tex", tex(land) bdec(3) nocon label	
reg job_unemployedold job_unemployed
outreg2 using "Table5_PanelB.tex", tex(land) bdec(3) nocon label	
reg educ_less_13old educ_less_13
outreg2 using "Table5_PanelB.tex", tex(land) bdec(3) nocon label	
reg educ_13old educ_13
outreg2 using "Table5_PanelB.tex", tex(land) bdec(3) nocon label	
reg educ_14_18old educ_14_18
outreg2 using "Table5_PanelB.tex", tex(land) bdec(3) nocon label	
erase "Table5_PanelA.txt"
erase "Table5_PanelB.txt"



*** T 6 - MGMT on Components of Surplus (in south) - Diff-in-Diff
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "Table6.txt"
cap erase "Table6.tex"
keep if year_normalized>=-4 & year_normalized<=4 & area=="south"
foreach y in expenditure_tot ///
			 expenditure_current expenditure_capital expenditure_other  ///
			 revenue_tot ///
			 revenue_tax revenue_transfer revenue_other {
reghdfe `y'_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
 	su `y'_w if e(sample)==1 & post==0
	local m`y'_w = r(mean)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun= r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
	outreg2 using "Table6.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', Mean Outcome Pre, `m`y'_w', Standardized Effect, `standard') ///
		bdec(3) /*adec(3)*/ nocon label		
}
erase "Table6.txt"



**** T 7 - Service Quality
use "Carreri_JOP_Panel.dta", clear
cap erase "Table7.txt"
cap erase "Table7.tex"
* 1) South
 reghdfe sose_rank post_mgmt post if area=="south", ///
  absorb(municipality_id year_normalized i.post#c.pia) ///
  vce(cluster municipality_id)  keepsingletons 
 	su sose_rank if e(sample)==1 & post==0
	local msose_rank=r(mean)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
 outreg2 using "Table7.tex", tex   ///
		addstat(Municipalities, `num_mun', Mean Outcome Pre, `msose_rank', Standardized Effect, `standard') ///
 		keep(post_mgmt) addtext(Sample, South)  /// 
 	    bdec(3) adec(3) nocon label
* 2) North
 reghdfe sose_rank post_mgmt post if area=="north", ///
  absorb(municipality_id year_normalized i.post#c.pia) ///
  vce(cluster municipality_id)  keepsingletons 
 	su sose_rank if e(sample)==1 & post==0
	local msose_rank=r(mean)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
 outreg2 using "Table7.tex", tex   ///
		addstat(Municipalities, `num_mun', Mean Outcome Pre, `msose_rank', Standardized Effect, `standard') ///
 		keep(post_mgmt) addtext(Sample, North)  /// 
 	    bdec(3) adec(3) nocon label
* 3) Centre
 reghdfe sose_rank post_mgmt post if area=="centre", ///
  absorb(municipality_id year_normalized i.post#c.pia) ///
  vce(cluster municipality_id)  keepsingletons 
 	su sose_rank if e(sample)==1 & post==0
	local msose_rank=r(mean)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
 outreg2 using "Table7.tex", tex   ///
		addstat(Municipalities, `num_mun', Mean Outcome Pre, `msose_rank', Standardized Effect, `standard') ///
 		keep(post_mgmt) addtext(Sample, Centre)  /// 
 	    bdec(3) adec(3) nocon label
erase "Table7.txt"




*** T 8 - Social Capital + Mafia + Letters
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "Table8.txt"
cap erase "Table8.tex"
gen post_mgmt_p1 = post_mgmt*low_social_capital
gen post_p1 = post*low_social_capital
gen mgmt_p1 = mgmt*low_social_capital
gen post_south=post*south
gen post_mgmt_south=post_mgmt*south
*** SOCIAL CAPITAL
reghdfe surplus_w post_mgmt_p1 post_mgmt post_p1 mgmt_p1 , ///
 absorb(municipality_id year year_normalized i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id i.post#i.region_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1 & low_social_capital==1
	local standard =r(sd)*(_b[post_mgmt_p1]+_b[post_mgmt])
outreg2 using "Table8.tex", tex(land)   ///
		keep(post_mgmt_p1 post_mgmt_south post_mgmt post_p1 post_south)  /// 
		addstat(Municipalities, `num_mun', SD DV Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
reghdfe surplus_w post_mgmt_south post_mgmt_p1 post_mgmt post_south post_p1 mgmt_p1, ///
 absorb(municipality_id year year_normalized i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id i.post#i.region_id) ///
   vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1 & low_social_capital==1
	local standard =r(sd)*(_b[post_mgmt_p1]+_b[post_mgmt])
outreg2 using "Table8.tex", tex(land)   ///
		keep(post_mgmt_p1 post_mgmt_south post_mgmt post_p1 post_south )  /// 
		addstat(Municipalities, `num_mun', SD DV Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
*** MAFIA
gen post_mgmt_mafia = post_mgmt*mafia
gen post_mafia = post*mafia
gen mgmt_mafia = mgmt*mafia
reghdfe surplus_w post_mgmt_mafia post_mgmt post_mafia mgmt_mafia ///
  if area=="south", ///
  absorb(municipality_id year year_normalized i.post#c.pia ///
 i.post#i.region_id i.post#i.party_id ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
  	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1 & mafia==1
	local standard =r(sd)*(_b[post_mgmt_mafia]+_b[post_mgmt])
outreg2 using "Table8.tex", tex(land)   ///
 keep(post_mgmt_p1 post_mgmt_south post_mgmt post_p1 post_south post_mgmt_mafia post_mgmt post_mafia)  /// 
 addstat(Municipalities, `num_mun', SD DV Pre, `msurplus_w', Standardized Effect, `standard') ///
 bdec(3) adec(3) nocon label
*** LETTER
gen post_mgmt_noletter = post_mgmt*noletter
gen post_noletter = post*noletter
gen mgmt_noletter = mgmt*noletter
reghdfe surplus_w post_mgmt_noletter post_mgmt post_noletter mgmt_noletter, ///
 absorb(municipality_id year year_normalized i.post#c.pia ///
 i.post#i.region_id i.post#i.party_id ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
  	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1 & noletter==1
	local standard =r(sd)*(_b[post_mgmt_noletter]+_b[post_mgmt])
outreg2 using "Table8.tex", tex(land)   ///
 keep(post_mgmt_p1 post_mgmt_south post_mgmt post_p1 post_south ///
	  post_mgmt_mafia post_mgmt post_mafia post_mgmt_noletter ///
	  post_mgmt post_noletter ) /// 
	  addstat(Municipalities, `num_mun', SD DV Pre, `msurplus_w', Standardized Effect, `standard') ///
	  bdec(3) adec(3) nocon label	
erase "Table8.txt"
			 
			 
			
**************************************************
*                APPENDIX TS                 *
**************************************************	


*** T A1 - Summary Stats
set more off
cap erase "TableA1.tex"
 * Cross-sectional variables
  use "Carreri_JOP_Cross.dta", clear
  reg surplus_w mgmt
  keep if e(sample)
  duplicates drop municipality_id area, force
  sutex mgmt mgmtw age female job_high job_low job_unemployed ///
		educ_less_13 educ_13 educ_14_18 exp_total year_of_term ///
		party_left_ext party_left_cnt party_cnt party_right_cnt party_right_ext pia ///
		population low_social_capital noletter mafia ,  ///
		nobs minmax label dig(2) file(TableA1)
 * Panel variables
  use "Carreri_JOP_Panel.dta", clear
  preserve
  reghdfe surplus_w post_mgmt, absorb(municipality_id year year_normalized) ///
	vce(cluster municipality_id)  keepsingletons 
  keep if e(sample)
  sutex surplus_w expenditure_tot_w revenue_tot_w  ///
			 expenditure_current_w expenditure_capital_w expenditure_other_w  ///
			 revenue_tax_w revenue_transfer_w revenue_other_w , ///
			 nobs minmax label  dig(2) file(TableA1) append
 restore
 reghdfe sose_rank post_mgmt post, absorb(municipality_id year_normalized) ///
	vce(cluster municipality_id)  keepsingletons 
 keep if e(sample)
 sutex sose_rank , nobs minmax label  dig(2) file(TableA1) append
* Calculate w/in and b/in variance for data section p.9
preserve
use "Carreri_JOP_Cross.dta", clear
duplicates drop municipality_id, force
encode area, gen(area_id)
xtset area_id
xtsum mgmt
restore



*** T A2 - Summary Stats South
set more off
cap erase "TableA2.tex"
 * Cross-sectional variables
  use "Carreri_JOP_Cross.dta", clear
  reg surplus_w mgmt if areea=="south"
  keep if e(sample)
  duplicates drop municipality_id area, force
  sutex mgmt mgmtw age female job_high job_low job_unemployed ///
		educ_less_13 educ_13 educ_14_18 exp_total year_of_term ///
		party_left_ext party_left_cnt party_cnt party_right_cnt party_right_ext pia ///
		population low_social_capital noletter mafia ,  ///
		nobs minmax label dig(2) file(TableA2)
 * Panel variables
  use "Carreri_Panel_Data.dta", clear
  preserve
  reghdfe surplus_w post_mgmt if area=="south", ///
	absorb(municipality_id year year_normalized) ///
	vce(cluster municipality_id)  keepsingletons 
  keep if e(sample)
  sutex surplus_w expenditure_tot_w revenue_tot_w  ///
		expenditure_current_w expenditure_capital_w expenditure_other_w  ///
		revenue_tax_w revenue_transfer_w revenue_other_w , ///
		nobs minmax label  dig(2) file(TableA2) append
 restore
 reghdfe sose_rank post_mgmt post if area=="south", ///
 absorb(municipality_id year_normalized) vce(cluster municipality_id) keepsingletons 
 keep if e(sample)
 sutex sose_rank , nobs minmax label  dig(2) file(TableA2) append
 
 
 
 *** T A3 - Summary Stats North
set more off
cap erase "TableA3.tex"
 * Cross-sectional variables
  use "Carreri_JOP_Cross.dta", clear
  reg surplus_w mgmt if areea=="north"
  keep if e(sample)
  duplicates drop municipality_id area, force
  sutex mgmt mgmtw age female job_high job_low job_unemployed ///
		educ_less_13 educ_13 educ_14_18 exp_total year_of_term ///
		party_left_ext party_left_cnt party_cnt party_right_cnt party_right_ext pia ///
		population low_social_capital noletter ,  ///
		nobs minmax label dig(2) file(TableA3)
 * Panel variables
  use "Carreri_Panel_Data.dta", clear
  preserve
  reghdfe surplus_w post_mgmt if area=="north", ///
	absorb(municipality_id year year_normalized) ///
	vce(cluster municipality_id)  keepsingletons 
  keep if e(sample)
  sutex surplus_w expenditure_tot_w revenue_tot_w  ///
		expenditure_current_w expenditure_capital_w expenditure_other_w  ///
		revenue_tax_w revenue_transfer_w revenue_other_w , ///
		nobs minmax label  dig(2) file(TableA3) append
 restore
 reghdfe sose_rank post_mgmt post if area=="north", ///
 absorb(municipality_id year_normalized) vce(cluster municipality_id) keepsingletons 
 keep if e(sample)
 sutex sose_rank , nobs minmax label  dig(2) file(TableA3) append
 
 
 
*** T A4 - Summary Stats Center
set more off
cap erase "TableA4.tex"
 * Cross-sectional variables
  use "Carreri_JOP_Cross.dta", clear
  reg surplus_w mgmt if areea=="centre"
  keep if e(sample)
  duplicates drop municipality_id area, force
  sutex mgmt mgmtw age female job_high job_low job_unemployed ///
		educ_less_13 educ_13 educ_14_18 exp_total year_of_term ///
		party_left_ext party_left_cnt party_cnt party_right_cnt party_right_ext pia ///
		population low_social_capital noletter ,  ///
		nobs minmax label dig(2) file(TableA4)
 * Panel variables
  use "Carreri_Panel_Data.dta", clear
  preserve
  reghdfe surplus_w post_mgmt if area=="centre", ///
	absorb(municipality_id year year_normalized) ///
	vce(cluster municipality_id)  keepsingletons 
  keep if e(sample)
  sutex surplus_w expenditure_tot_w revenue_tot_w  ///
		expenditure_current_w expenditure_capital_w expenditure_other_w  ///
		revenue_tax_w revenue_transfer_w revenue_other_w , ///
		nobs minmax label  dig(2) file(TableA4) append
 restore
 reghdfe sose_rank post_mgmt post if area=="centre", ///
 absorb(municipality_id year_normalized) vce(cluster municipality_id) keepsingletons 
 keep if e(sample)
 sutex sose_rank , nobs minmax label  dig(2) file(TableA4) append
 
 




*** T A5 - correlation b/w MGMT and other measures of quality (Validity)
set more off
use "Carreri_JOP_Cross.dta", clear
cap erase "TableA5.tex"
cap erase "TableA5.txt"
tab year_of_term, gen(year_of_term_)
forvalues x=1(1)5{
label var year_of_term_`x' "Year of Current Term - `x'"
}
duplicates drop municipality_id, force
* column 1 
reg mgmt age female
 outreg2 using "TableA5.tex", ///
		 keep(age female) ///
		 bdec(3) addtext(Area FE, No) label
* column 2
reg mgmt age female educ_13 educ_14_18
 test educ_13= educ_14_18
 outreg2 using "TableA5.tex", ///
		 keep(age female educ_13 educ_14_18) ///
		 bdec(3) addtext(Area FE, No) label
test educ_13==educ_14_18
* column 3
reg mgmt age female educ_13 educ_14_18 job_high job_low 
 test job_high=job_low
 outreg2 using "TableA5.tex", ///
		 keep(age female educ_13 educ_14_18 job_high job_low) ///
		 bdec(3) addtext(Area FE, No) label
test job_high==job_low
* column 4
reg mgmt age female educ_13 educ_14_18 job_high job_low  exp_total 
 outreg2 using "TableA5.tex", ///
		 keep(age female educ_13 educ_14_18 job_high job_low  exp_total ///
		 north centre) ///
		 bdec(3) addtext(Area FE, No) label
* column 5
reg mgmt age female educ_13 educ_14_18 job_high job_low  exp_total ///
 party_left_ext party_left_cnt  party_right_cnt party_right_ext
 outreg2 using "TableA5.tex", ///
		 keep(age female educ_13 educ_14_18 job_high job_low  exp_total ///
		 north centre party_left_ext party_left_cnt party_right_cnt party_right_ext) ///
		 bdec(3) addtext(Area FE, No) label
* column 6
reg mgmt age female educ_13 educ_14_18 job_high job_low  exp_total ///
  party_left_ext party_left_cnt  party_right_cnt party_right_ext year_of_term_2-year_of_term_5
 outreg2 using "TableA5.tex", ///
		 keep(age female educ_13 educ_14_18 job_high job_low  exp_total ///
		 north centre year_of_term_2-year_of_term_5 party_left_ext party_left_cnt party_right_cnt party_right_ext) ///
		 bdec(3) addtext(Area FE, No) label
* column 7
reg mgmt age female educ_13 educ_14_18 job_high job_low  exp_total ///
  party_left_ext party_left_cnt  party_right_cnt party_right_ext year_of_term_2-year_of_term_5 ///
  i.region_id
 outreg2 using "TableA5.tex", ///
		 keep(age female educ_13 educ_14_18 job_high job_low  exp_total ///
		 north centre year_of_term_2-year_of_term_5 party_left_ext party_left_cnt party_right_cnt party_right_ext) ///
		 bdec(3) addtext(Area FE, Yes) label
erase "TableA5.txt"




*** T A6 - Validity of Competence Score: PCA of 7 questions
set more off
use "Carreri_JOP_Cross.dta", clear
pca q1 q2 q3 q4 q5 q6 q7
egen num_mun=nvals(municipality_id) 
su num_mun





*** T A7 - Reliability of Competence Score
set more off
use "Carreri_JOP_Cross.dta", clear
duplicates drop municipality_id, force
reg mgmt_target mgmt_operations 
reg mgmt_target mgmt_monitoring 
reg mgmt_target mgmt_people
reg mgmt_operations mgmt_monitoring
reg mgmt_operations mgmt_people
reg mgmt_monitoring mgmt_people




*** T A8 - Balance b/w takers and non-takers
use "Carreri_JOP_interviewed_and_not.dta", clear
cap erase "TableA8.txt"
cap erase "TableA8.tex"
balancetable interviewed age female ///
			 job_high job_low job_unemployed ///
			 educ_less_13 educ_13 educ_14_18 ///
			 revenue_w expenditure_w surplus_w ///
			 using "TableA8.tex", ///
			 format(%4.2f) varlabels staraux wide replace




*** T A9 - Balance b/w takers and non-takers by area
use "Carreri_JOP_interviewed_and_not.dta", clear
foreach x in south north centre {
cap erase "TableA9_Panel`x'.txt"
cap erase "TableA9_Panel`x'.tex"
preserve
	keep if area=="`x'"
	balancetable interviewed age female ///
				job_high job_low job_unemployed ///
				educ_less_13 educ_13 educ_14_18 ///
				revenue_w expenditure_w surplus_w ///
				using "TableA9_Panel`x'.tex", ///
				format(%4.2f) varlabels staraux wide replace
restore
}


*** T A10 - Balance b/w takers and all comparable mayors in Italy
use "Carreri_JOP_interviewed_and_not_all_Italy.dta", clear
cap erase "TableA10.txt"
cap erase "TableA10.tex"
balancetable interviewed age female ///
			 job_high job_low job_unemployed ///
			 educ_less_13 educ_13 educ_14_18 ///
			 revenue_w expenditure_w surplus_w ///
			 using "TableA10.tex", ///
			 format(%4.2f) varlabels staraux wide replace




**** T A11 - Heterogeneous effect for Cross-section
set more off
use "Carreri_JOP_Cross.dta", clear
cap erase "TableA11.tex"
cap erase "TableA11.txt"
gen mgmt_northcentre = mgmt*northcentre
gen mgmt_south = mgmt*south
foreach y in surplus_w {
* 1
reghdfe `y' mgmt_south mgmt south pia,  ///
		absorb(i.year i.region_id) ///
		vce(cluster municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1 & south==1
	local standard =r(sd)*(_b[mgmt_south]+_b[mgmt])
outreg2 using "TableA11.tex", tex(land)  ///
		keep(mgmt_south mgmt south northcentre)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') nocon label bdec(3) adec(3)	
* 2
reghdfe `y' mgmt_south mgmt south pia ///
		female age job_high job_low educ_13 educ_14_18 exp_total, ///
		absorb(i.year i.region_id) ///
		vce(cluster municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1 & south==1
	local standard =r(sd)*(_b[mgmt_south]+_b[mgmt])
outreg2 using "TableA11.tex", tex(land)  ///
		keep(mgmt_south mgmt south northcentre)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') nocon label bdec(3) adec(3)	
* 3
reghdfe `y' mgmt_south mgmt south pia ///
		female age job_high job_low educ_13 educ_14_18 exp_total, ///
		absorb(i.year i.region_id i.party_id) ///
		vce(cluster municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1 & south==1
	local standard =r(sd)*(_b[mgmt_south]+_b[mgmt])
outreg2 using "TableA11.tex", tex(land)   ///
		keep(mgmt_south mgmt south northcentre)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') nocon label bdec(3) adec(3)
* 4
reghdfe `y' mgmt_south mgmt south pia ///
		female age job_high job_low educ_13 educ_14_18 exp_total, ///
		absorb(i.year i.region_id i.party_id i.year_of_term) ///
		vce(cluster municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1 & south==1
	local standard =r(sd)*(_b[mgmt_south]+_b[mgmt])
outreg2 using "TableA11.tex", tex(land)  ///
		keep(mgmt_south mgmt south northcentre)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') nocon label bdec(3) adec(3)			
}
erase "TableA11.txt"





*** T A12 - Heterogeneous Effect with South: Diff-in-Diff
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "TableA12.tex"
cap erase "TableA12.txt"
foreach x in south  northcentre {
gen post_mgmt_`x' = post_mgmt*`x'
gen post_`x' = post*`x'
}
* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe surplus_w post_mgmt_south post_mgmt post_south, ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1 & south==1
	local standard =r(sd)*(_b[post_mgmt_south]+_b[post_mgmt])
outreg2 using "TableA12.tex", tex(land)   ///
		keep(post_mgmt_south post_mgmt post_south)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 2 - baseline + region FE
reghdfe surplus_w post_mgmt_south post_mgmt post_south, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1 & south==1
	local standard =r(sd)*(_b[post_mgmt_south]+_b[post_mgmt])
outreg2 using "TableA12.tex", tex(land)   ///
		keep(post_mgmt_south post_mgmt post_south)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label		
* column 3 - baseline + region FE + mayor controls
reghdfe surplus_w post_mgmt_south post_mgmt post_south, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1 & south==1
	local standard =r(sd)*(_b[post_mgmt_south]+_b[post_mgmt])
outreg2 using "TableA12.tex", tex(land)   ///
		keep(post_mgmt_south post_mgmt post_south)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe surplus_w post_mgmt_south post_mgmt post_south, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1 & south==1
	local standard =r(sd)*(_b[post_mgmt_south]+_b[post_mgmt])
outreg2 using "TableA12.tex", tex(land)   ///
		keep(post_mgmt_south post_mgmt post_south)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label			
erase "TableA12.txt"



*** T A13 - Robustness to Inverse Covariance-Weighted Mgmt Score - Cross
set more off
use "Carreri_JOP_Cross.dta", clear
cap erase "TableA13_Panelfull.tex"
cap erase "TableA13_Panelfull.txt"
foreach y in surplus_w {
* column 1 - baseline (year and region FE)
reg `y' mgmtw i.year i.region_id pia ///
		, cl(municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[mgmtw]
	outreg2 using "TableA13_Panelfull.tex", tex(land) keep(mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
* column 2 - baseline + mayor controls 
reg `y' mgmtw  i.year i.region_id pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		, cl(municipality_id) 
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[mgmtw]
	outreg2 using "TableA13_Panelfull.tex", tex(land) keep(mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
* column 3 - baseline + mayor controls + mayor party FE
reg `y' mgmtw  i.year i.region_id i.party_id pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		, cl(municipality_id) 
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[mgmtw]
	outreg2 using "TableA13_Panelfull.tex", tex(land) keep(mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
* column 4 - baseline + mayor controls + mayor party FE + year_of_term FE
reg `y' mgmtw  i.year i.region_id i.party_id i.year_of_term  pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		, cl(municipality_id) 
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[mgmtw]
	outreg2 using "TableA13_Panelfull.tex", tex(land) keep(mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
		
* South/North/Centre if area=="`x'"
foreach x in south north centre {
cap erase "TableA13_Panel`x'.tex"
cap erase "TableA13_Panel`x'.txt"
* column 1 - baseline (year and region FE)
reg `y' mgmtw i.year i.region_id pia ///
		if area=="`x'" , cl(municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[mgmtw]
	outreg2 using "TableA13_Panel`x'.tex", tex(land) keep(mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
* column 2 - baseline + mayor controls
reg `y' mgmtw i.year i.region_id pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		if area=="`x'" , cl(municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[mgmtw]
	outreg2 using "TableA13_Panel`x'.tex", tex(land) keep(mgmtw) /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
* column 3 - baseline + mayor controls + mayor party FE
reg `y' mgmtw i.year i.region_id i.party_id pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		if area=="`x'" , cl(municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[mgmtw]
		outreg2 using "TableA13_Panel`x'.tex", tex(land) keep(mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
* column 4 - baseline + mayor controls + mayor party FE + year_of_term FE
reg `y' mgmtw i.year i.region_id i.party_id i.year_of_term pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		if area=="`x'" , cl(municipality_id)	
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[mgmtw]
		outreg2 using "TableA13_Panel`x'.tex", tex(land) keep(mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
erase "TableA13_Panel`x'.txt"
}
erase "TableA13_Panelfull.txt"
}



*** T A14 - Robustness to Inverse Covariance-Weighted Mgmt Score - D-i-D
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "TableA14_Panelfull.txt"
cap erase "TableA14_Panelfull.tex"
* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe surplus_w post_mgmtw, ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[post_mgmtw]
outreg2 using "TableA14_Panelfull.tex", tex(land)   ///
		keep(post_mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 2 - baseline + region FE
reghdfe surplus_w post_mgmtw, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[post_mgmtw]
outreg2 using "TableA14_Panelfull.tex", tex(land)   ///
		keep(post_mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label		
* column 3 - baseline + region FE + mayor controls
reghdfe surplus_w post_mgmtw, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[post_mgmtw]
outreg2 using "TableA14_Panelfull.tex", tex(land)   ///
		keep(post_mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe surplus_w post_mgmtw, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[post_mgmtw]
outreg2 using "TableA14_Panelfull.tex", tex(land)   ///
		keep(post_mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label			
erase "TableA14_Panelfull.txt"
foreach x in south north centre {
cap erase "TableA14_Panel`x'.txt"
cap erase "TableA14_Panel`x'.tex"
* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe surplus_w post_mgmtw if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[post_mgmtw]
outreg2 using "TableA14_Panel`x'.tex", tex(land)   ///
		keep(post_mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 2 - baseline + region FE
reghdfe surplus_w post_mgmtw if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[post_mgmtw]
outreg2 using "TableA14_Panel`x'.tex", tex(land)   ///
		keep(post_mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 3 - baseline + region FE + mayor controls
reghdfe surplus_w post_mgmtw if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[post_mgmtw]
outreg2 using "TableA14_Panel`x'.tex", tex(land)   ///
		keep(post_mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe surplus_w post_mgmtw if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmtw if e(sample)==1
	local standard =r(sd)*_b[post_mgmtw]
outreg2 using "TableA14_Panel`x'.tex", tex(land)   ///
		keep(post_mgmtw)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label			
erase "TableA14_Panel`x'.txt"
}





*** T A15 - Robustness to Latent Score (Factor Analsyis) - D-i-D
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "TableA15_Panelfull.txt"
cap erase "TableA15_Panelfull.tex"
factor q1 q2 q3 q4 q5 q6 q7, ml
rotate
predict f1
gen post_f1=post*f1

* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe surplus_w post_f1, ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
outreg2 using "TableA15_Panelfull.tex", tex(land)   ///
		keep(post_f1)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w') ///
		bdec(3) nocon label	
* column 2 - baseline + region FE
reghdfe surplus_w post_f1, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
outreg2 using "TableA15_Panelfull.tex", tex(land)   ///
		keep(post_f1)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w') ///
		bdec(3) nocon label		
* column 3 - baseline + region FE + mayor controls
reghdfe surplus_w post_f1, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
outreg2 using "TableA15_Panelfull.tex", tex(land)   ///
		keep(post_f1)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w') ///
		bdec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe surplus_w post_f1, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
outreg2 using "TableA15_Panelfull.tex", tex(land)   ///
		keep(post_f1)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w') ///
		bdec(3) nocon label			
erase "TableA15_Panelfull.txt"
foreach x in south north centre {
cap erase "TableA15_Panel`x'.txt"
cap erase "TableA15_Panel`x'.tex"
* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe surplus_w post_f1 if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
outreg2 using "TableA15_Panel`x'.tex", tex(land)   ///
		keep(post_f1)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w') ///
		bdec(3) nocon label	
* column 2 - baseline + region FE
reghdfe surplus_w post_f1 if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
outreg2 using "TableA15_Panel`x'.tex", tex(land)   ///
		keep(post_f1)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w') ///
		bdec(3) nocon label	
* column 3 - baseline + region FE + mayor controls
reghdfe surplus_w post_f1 if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
outreg2 using "TableA15_Panel`x'.tex", tex(land)   ///
		keep(post_f1)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w') ///
		bdec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe surplus_w post_f1 if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
outreg2 using "TableA15_Panel`x'.tex", tex(land)   ///
		keep(post_f1)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w') ///
		bdec(3) nocon label			
erase "TableA15_Panel`x'.txt"
}



*** T A16 - Reliability: exclude one practice or one question at a time
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "TableA16_PanelA.txt"
cap erase "TableA16_PanelA.tex"
cap erase "TableA16_PanelB.txt"
cap erase "TableA16_PanelB.tex"
keep if year_normalized>=-4 & year_normalized<=4 & area=="south"
* Panel A
egen mgmt_1 = rowmean(mgmt_operations mgmt_monitoring mgmt_people)
egen mgmt_2 = rowmean(mgmt_target mgmt_monitoring mgmt_people)
egen mgmt_3 = rowmean(mgmt_target mgmt_operations mgmt_people)
egen mgmt_4 = rowmean(mgmt_target mgmt_operations mgmt_monitoring)
forvalues x=1(1)4{
gen post_mgmt_not1 = post*mgmt_`x'
label var post_mgmt_not1 "Competence Score (excluding one practice) X Post"
reghdfe surplus_w post_mgmt_not1, ///
		absorb(municipality_id year year_normalized i.post#c.pia ///
		i.post#i.region_id ///
		i.post#c.female i.post#c.age i.post#c.job_high i.post#c.job_low ///
		i.post#c.educ_13 i.post#c.educ_14_18 i.post#c.exp_total ///
		i.post#i.party_id) ///
		vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt_`x' if e(sample)==1
	local standard =r(sd)*_b[post_mgmt_not1]
outreg2 using "TableA16_PanelA.tex", tex(land)    ///
		keep(post_mgmt_not1)  /// 
		addstat(Municipalities,`num_mun',SD Surplus Pre,`msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
drop post_mgmt_not1
}
erase "TableA16_PanelA.txt"
* Panel B
egen mgmt_but_one_1 = rowmean(q2 q3 q4 q5 q6 q7)
egen mgmt_but_one_2 = rowmean(q1 q3 q4 q5 q6 q7)
egen mgmt_but_one_3 = rowmean(q1 q2 q4 q5 q6 q7)
egen mgmt_but_one_4 = rowmean(q1 q2 q3 q5 q6 q7)
egen mgmt_but_one_5 = rowmean(q1 q2 q3 q4 q6 q7)
egen mgmt_but_one_6 = rowmean(q1 q2 q3 q4 q5 q7)
egen mgmt_but_one_7 = rowmean(q1 q2 q3 q4 q5 q6)
forvalues x=1(1)7{
gen post_mgmt_but_one = post*mgmt_but_one_`x'
label var post_mgmt_but_one "Competence Score (excluding one question) X Post"

reghdfe surplus_w post_mgmt_but_one, ///
		absorb(municipality_id year year_normalized i.post#c.pia ///
		i.post#i.region_id ///
		i.post#c.female i.post#c.age i.post#c.job_high i.post#c.job_low ///
		i.post#c.educ_13 i.post#c.educ_14_18 i.post#c.exp_total ///
		i.post#i.party_id) ///
		vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt_but_one_`x' if e(sample)==1
	local standard =r(sd)*_b[post_mgmt_but_one]
outreg2 using "TableA16_PanelB.tex", tex(land)    ///
		keep(post_mgmt_but_one)  /// 
		addstat(Municipalities,`num_mun',SD Surplus Pre,`msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
drop post_mgmt_but_one
}
erase "TableA16_PanelB.txt"	





*** T A17 - Effect of Individual Components of the Score
set more off
use "Carreri_JOP_Panel.dta", clear
foreach a in target operations monitoring people {
cap erase "TableA17_Panel`a'.txt"
cap erase "TableA17_Panel`a'.tex"
* column 1
 reghdfe surplus_w post_`a' if area=="south", ///
  absorb(municipality_id year year_normalized i.post#c.pia) ///
  vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt_`a' if e(sample)==1
	local standard =r(sd)*_b[post_`a']
 outreg2 using "TableA17_Panel`a'.tex", tex(land)   ///
  keep(post_`a')  /// 
  addstat(Municipalities,`num_mun',SD Surplus Pre,`msurplus_w', Standardized Effect, `standard') ///
  bdec(3) adec(3) nocon label	
* column 2
 reghdfe surplus_w post_`a' if area=="south", ///
  absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
  vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt_`a' if e(sample)==1
	local standard =r(sd)*_b[post_`a']
 outreg2 using "TableA17_Panel`a'.tex", tex(land)   ///
  keep(post_`a')  /// 
  addstat(Municipalities,`num_mun',SD Surplus Pre,`msurplus_w', Standardized Effect, `standard') ///
  bdec(3) adec(3) nocon label	
* column 3
 reghdfe surplus_w post_`a' if area=="south", ///
  absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
   i.post#c.female  i.post#c.age ///
   i.post#c.job_high i.post#c.job_low ///
   i.post#c.educ_13 i.post#c.educ_14_18 ///
   i.post#c.exp_total) ///
  vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt_`a' if e(sample)==1
	local standard =r(sd)*_b[post_`a']
 outreg2 using "TableA17_Panel`a'.tex", tex(land)   ///
  keep(post_`a')  /// 
  addstat(Municipalities,`num_mun',SD Surplus Pre,`msurplus_w', Standardized Effect, `standard') ///
  bdec(3) adec(3) nocon label	
* column 4
 reghdfe surplus_w post_`a' if area=="south", ///
  absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
   i.post#c.female  i.post#c.age ///
   i.post#c.job_high i.post#c.job_low ///
   i.post#c.educ_13 i.post#c.educ_14_18 ///
   i.post#c.exp_total i.post#i.party_id) ///
  vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt_`a' if e(sample)==1
	local standard =r(sd)*_b[post_`a']
 outreg2 using "TableA17_Panel`a'.tex", tex(land)   ///
  keep(post_`a')  /// 
  addstat(Municipalities,`num_mun',SD Surplus Pre,`msurplus_w', Standardized Effect, `standard') ///
  bdec(3) adec(3) nocon label
 erase "TableA17_Panel`a'.txt"
}



*** T A18 - MGMT and previous mayor's covariates in North
use "Carreri_JOP_Cross.dta", clear
duplicates drop municipality_id, force
cap erase "TableA18_PanelA.txt"
cap erase "TableA18_PanelA.tex"
cap erase "TableA18_PanelB.txt"
cap erase "TableA18_PanelB.tex"
* Panel A
reg ageold mgmt if area=="north"
outreg2 using "TableA18_PanelA.tex", tex(land) bdec(3) nocon label	
reg job_highold mgmt if area=="north"
outreg2 using "TableA18_PanelA.tex", tex(land) bdec(3) nocon label	
reg job_lowold mgmt if area=="north"
outreg2 using "TableA18_PanelA.tex", tex(land) bdec(3) nocon label	
reg job_unemployedold mgmt if area=="north"
outreg2 using "TableA18_PanelA.tex", tex(land) bdec(3) nocon label	
reg educ_less_13old mgmt if area=="north"
outreg2 using "TableA18_PanelA.tex", tex(land) bdec(3) nocon label	
reg educ_13old mgmt if area=="north"
outreg2 using "TableA18_PanelA.tex", tex(land) bdec(3) nocon label	
reg educ_14_18old mgmt if area=="north"
outreg2 using "TableA18_PanelA.tex", tex(land) bdec(3) nocon label	
* Panel B
reg ageold age if area=="north"
outreg2 using "TableA18_PanelB.tex", tex(land) bdec(3) nocon label	
reg job_highold job_high if area=="north"
outreg2 using "TableA18_PanelB.tex", tex(land) bdec(3) nocon label	
reg job_lowold job_low if area=="north"
outreg2 using "TableA18_PanelB.tex", tex(land) bdec(3) nocon label	
reg job_unemployedold job_unemployed if area=="north"
outreg2 using "TableA18_PanelB.tex", tex(land) bdec(3) nocon label	
reg educ_less_13old educ_less_13 if area=="north"
outreg2 using "TableA18_PanelB.tex", tex(land) bdec(3) nocon label	
reg educ_13old educ_13 if area=="north"
outreg2 using "TableA18_PanelB.tex", tex(land) bdec(3) nocon label	
reg educ_14_18old educ_14_18 if area=="north"
outreg2 using "TableA18_PanelB.tex", tex(land) bdec(3) nocon label	
erase "TableA18_PanelA.txt"
erase "TableA18_PanelB.txt"

	
	
	
*** T A19 - MGMT and previous mayor's covariates in Center
use "Carreri_JOP_Cross.dta", clear
duplicates drop municipality_id, force
cap erase "TableA19_PanelA.txt"
cap erase "TableA19_PanelA.tex"
cap erase "TableA19_PanelB.txt"
cap erase "TableA19_PanelB.tex"
* Panel A
reg ageold mgmt if area=="centre"
outreg2 using "TableA19_PanelA.tex", tex(land) bdec(3) nocon label	
reg job_highold mgmt if area=="centre"
outreg2 using "TableA19_PanelA.tex", tex(land) bdec(3) nocon label	
reg job_lowold mgmt if area=="centre"
outreg2 using "TableA19_PanelA.tex", tex(land) bdec(3) nocon label	
reg job_unemployedold mgmt if area=="centre"
outreg2 using "TableA19_PanelA.tex", tex(land) bdec(3) nocon label	
reg educ_less_13old mgmt if area=="centre"
outreg2 using "TableA19_PanelA.tex", tex(land) bdec(3) nocon label	
reg educ_13old mgmt if area=="centre"
outreg2 using "TableA19_PanelA.tex", tex(land) bdec(3) nocon label	
reg educ_14_18old mgmt if area=="centre"
outreg2 using "TableA19_PanelA.tex", tex(land) bdec(3) nocon label	
* Panel B
reg ageold age if area=="centre"
outreg2 using "TableA19_PanelB.tex", tex(land) bdec(3) nocon label	
reg job_highold job_high if area=="centre"
outreg2 using "TableA19_PanelB.tex", tex(land) bdec(3) nocon label	
reg job_lowold job_low if area=="centre"
outreg2 using "TableA19_PanelB.tex", tex(land) bdec(3) nocon label	
reg job_unemployedold job_unemployed if area=="centre"
outreg2 using "TableA19_PanelB.tex", tex(land) bdec(3) nocon label	
reg educ_less_13old educ_less_13 if area=="centre"
outreg2 using "TableA19_PanelB.tex", tex(land) bdec(3) nocon label	
reg educ_13old educ_13 if area=="centre"
outreg2 using "TableA19_PanelB.tex", tex(land) bdec(3) nocon label	
reg educ_14_18old educ_14_18 if area=="centre"
outreg2 using "TableA19_PanelB.tex", tex(land) bdec(3) nocon label	
erase "TableA19_PanelA.txt"
erase "TableA19_PanelB.txt"

	
	
	
*** T A20 - Competence Score vs. Human Capital Measures
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "TableA20.txt"
cap erase "TableA20.tex"
foreach z in female age job_high ///
			 educ_14_18 exp_total ///
			 job_low educ_13 ///
			 job_unemployed educ_less_13 {
gen post_`z' = post*`z'
}
label var post_female "Female x Post"
label var post_age "Age x Post"
label var post_job_high "Job - High Skill x Post"
label var post_job_low "Job - Low Skill x Post"
label var post_educ_14_18 "Education - University x Post"
label var post_educ_13 "Education - Highschool x Post"
label var post_exp_total "Years in Municipal Government x Post"
foreach x in south north centre {
reghdfe surplus_w post_mgmt post_female post_age ///
	post_job_high post_job_low post_educ_14_18 post_educ_13 ///
	post_exp_total if area=="`x'", ///
	absorb(municipality_id year year_normalized i.post#c.pia ///
	i.post#i.region_id i.post#i.party_id) ///
	vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA20.tex", tex(land)   ///
 keep(post_mgmt post_female post_age post_job_high post_job_low ///
	  post_educ_14_18 post_educ_13 post_exp_total ) /// 
 addstat(Municipalities,`num_mun',SD Surplus Pre,`msurplus_w', Standardized Effect, `standard') ///
 bdec(3) adec(3) nocon label	
}
erase "TableA20.txt"



*** T 21 - Robusteness to Balanced Sample
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "TableA21_Panelfull.txt"
cap erase "TableA21_Panelfull.tex"
bys municipality_id: egen max_year_normalized = max(year_normalized)
bys municipality_id: egen min_year_normalized = min(year_normalized)
tab max_year_normalized
tab min_year_normalized 
keep if max_year_normalized==4 & min_year_normalized==-4
* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA21_Panelfull.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 2 - baseline + region FE
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA21_Panelfull.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label		
* column 3 - baseline + region FE + mayor controls
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA21_Panelfull.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA21_Panelfull.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label			
erase "TableA21_Panelfull.txt"
foreach x in south north centre {
cap erase "TableA21_Panel`x'.txt"
cap erase "TableA21_Panel`x'.tex"
* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe surplus_w post_mgmt if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA21_Panel`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 2 - baseline + region FE
reghdfe surplus_w post_mgmt if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA21_Panel`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 3 - baseline + region FE + mayor controls
reghdfe surplus_w post_mgmt if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA21_Panel`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe surplus_w post_mgmt if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA21_Panel`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label			
erase "TableA21_Panel`x'.txt"
}



*** T A22 - Robustness to using absolute value of surplus
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "TableA22_Panelfull.txt"
cap erase "TableA22_Panelfull.tex"
gen abs_surplus_w = abs(surplus_w)
su surplus_w
label var abs_surplus_w "Surplus (Absolute Value)"
* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe abs_surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su abs_surplus_w if e(sample)==1 & post==0
	local mabs_surplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA22_Panelfull.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `mabs_surplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 2 - baseline + region FE
reghdfe abs_surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su abs_surplus_w if e(sample)==1 & post==0
	local mabs_surplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA22_Panelfull.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `mabs_surplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label		
* column 3 - baseline + region FE + mayor controls
reghdfe abs_surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su abs_surplus_w if e(sample)==1 & post==0
	local mabs_surplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA22_Panelfull.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `mabs_surplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe abs_surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su abs_surplus_w if e(sample)==1 & post==0
	local mabs_surplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA22_Panelfull.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `mabs_surplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label			
erase "TableA22_Panelfull.txt"
foreach x in south north centre {
cap erase "TableA22_Panel`x'.txt"
cap erase "TableA22_Panel`x'.tex"
* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe abs_surplus_w post_mgmt if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su abs_surplus_w if e(sample)==1 & post==0
	local mabs_surplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA22_Panel`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `mabs_surplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 2 - baseline + region FE
reghdfe abs_surplus_w post_mgmt if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su abs_surplus_w if e(sample)==1 & post==0
	local mabs_surplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA22_Panel`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `mabs_surplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 3 - baseline + region FE + mayor controls
reghdfe abs_surplus_w post_mgmt if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su abs_surplus_w if e(sample)==1 & post==0
	local mabs_surplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA22_Panel`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `mabs_surplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe abs_surplus_w post_mgmt if area=="`x'", ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su abs_surplus_w if e(sample)==1 & post==0
	local mabs_surplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA22_Panel`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `mabs_surplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label			
erase "TableA22_Panel`x'.txt"
}



*** T A23 - SOCIAL CAPITAL - MGMT on Surplus - Cross Section
set more off
use "Carreri_JOP_Cross.dta", clear
cap erase "TableA23_Panelfull.txt"
foreach y in surplus_w {
* column 1 - baseline (year and region FE)
reg `y' mgmt i.year i.region_id pia ///
		, cl(municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[mgmt]
	outreg2 using "TableA23_Panelfull.tex", tex(land) keep(mgmt)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
* column 2 - baseline + mayor controls 
reg `y' mgmt  i.year i.region_id pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		, cl(municipality_id) 
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[mgmt]
	outreg2 using "TableA23_Panelfull.tex", tex(land) keep(mgmt)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
* column 3 - baseline + mayor controls + mayor party FE
reg `y' mgmt  i.year i.region_id i.party_id pia  ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		, cl(municipality_id) 
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[mgmt]
	outreg2 using "TableA23_Panelfull.tex", tex(land) keep(mgmt)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
* column 4 - baseline + mayor controls + mayor party FE + year_of_term FE
reg `y' mgmt  i.year i.region_id i.party_id i.year_of_term pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		, cl(municipality_id) 
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[mgmt]
	outreg2 using "TableA23_Panelfull.tex", tex(land) keep(mgmt)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)		
* High/Low Social Capital if area=="`x'"
forvalues x=0/1 {
cap erase "TableA23_PanelLowSocialCapital`x'.tex"
cap erase "TableA23_PanelLowSocialCapital`x'.txt"
* column 1 - baseline (year and region FE)
reg `y' mgmt i.year i.region_id pia ///
		if low_social_capital==`x' , cl(municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[mgmt]
	outreg2 using "TableA23_PanelLowSocialCapital`x'.tex", tex(land) keep(mgmt)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
* column 2 - baseline + mayor controls
reg `y' mgmt i.year i.region_id pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		if low_social_capital==`x' , cl(municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[mgmt]
	outreg2 using "TableA23_PanelLowSocialCapital`x'.tex", tex(land) keep(mgmt) /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
* column 3 - baseline + mayor controls + mayor party FE
reg `y' mgmt i.year i.region_id i.party_id pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		if low_social_capital==`x' , cl(municipality_id)
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[mgmt]
		outreg2 using "TableA23_PanelLowSocialCapital`x'.tex", tex(land) keep(mgmt)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
* column 4 - baseline + mayor controls + mayor party FE + year_of_term FE
reg `y' mgmt i.year i.region_id i.party_id i.year_of_term pia ///
		female age job_high job_low educ_13 educ_14_18  exp_total ///
		if low_social_capital==`x' , cl(municipality_id)	
	su `y' if e(sample)==1
	local m`y' = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[mgmt]
		outreg2 using "TableA23_PanelLowSocialCapital`x'.tex", tex(land) keep(mgmt)  /// 
		addstat(Municipalities, `num_mun', SD DV, `m`y'', Standardized Effect, `standard') ///
		nocon label bdec(3) adec(3)
erase "TableA23_PanelLowSocialCapital`x'.txt"
}
erase "TableA23_Panelfull.txt"
}



*** T A24 - SOCIAL CAPITAL No difference in levels: MGMT on Surplus in Pre-period
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "TableA24.txt"
keep if year_normalized==-1|year_normalized==-2|year_normalized==-3|year_normalized==-4
forvalues i=1(1)4 {
 gen d`i'=mgmt*period_`i'
 label var d`i' "Mean Competence Score x year -`i'"
 }
 * Full
areg surplus_w d1-d4 , ///
 vce(cluster municipality_id) absorb(year_normalized)
	su surplus_w if e(sample)==1
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	outreg2 using "TableA24.tex",  bdec(3) nocon label /// 
		addstat(Municipalities, `num_mun', SD Surplus, `msurplus_w') ///
		ctitle("Surplus, Full Sample") replace
* Low Social Capital
areg surplus_w d1-d4 if low_social_capital==1, ///
 vce(cluster municipality_id) absorb(year_normalized)
	su surplus_w if e(sample)==1
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	outreg2 using "TableA24.tex",  bdec(3) nocon label ///
		addstat(Municipalities, `num_mun', SD Surplus, `msurplus_w') ///
		ctitle("Surplus, Low Social Capital") 
* High Social Capital
areg surplus_w d1-d4 if low_social_capital==0, ///
 vce(cluster municipality_id) absorb(year_normalized)
	su surplus_w if e(sample)==1
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	outreg2 using "TableA24.tex",  bdec(3) nocon label ///
		addstat(Municipalities, `num_mun', SD Surplus, `msurplus_w') ///
		ctitle("Surplus, High Social Capital") 
erase "TableA24.txt"



*** T A25 - SOCIAL CAPITAL - MGMT on Surplus - Diff-in-Diff
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "TableA25_Panelfull.txt"
* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA25_Panelfull.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 2 - baseline + region FE
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA25_Panelfull.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 3 - baseline + region FE + mayor controls
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA25_Panelfull.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA25_Panelfull.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
erase "TableA25_Panelfull.txt"
forvalues x=0/1  {
cap erase "TableA25_PanelLowSocialCapital`x'.txt"
cap erase "TableA25_PanelLowSocialCapital`x'.tex"
* column 1 - baseline (FE for municipality, year, normalized year)
reghdfe surplus_w post_mgmt if low_social_capital==`x', ///
 absorb(municipality_id year year_normalized i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA25_PanelLowSocialCapital`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 2 - baseline + region FE
reghdfe surplus_w post_mgmt if low_social_capital==`x', ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA25_PanelLowSocialCapital`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 3 - baseline + region FE + mayor controls
reghdfe surplus_w post_mgmt if low_social_capital==`x', ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA25_PanelLowSocialCapital`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
* column 4 - baseline + mayor controls + region FE + Mayor's party FE
reghdfe surplus_w post_mgmt if low_social_capital==`x', ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
	su surplus_w if e(sample)==1 & post==0
	local msurplus_w = r(sd)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA25_PanelLowSocialCapital`x'.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', SD Surplus Pre, `msurplus_w', Standardized Effect, `standard') ///
		bdec(3) adec(3) nocon label	
erase "TableA25_PanelLowSocialCapital`x'.txt"
}


*** T A26 - SOCIAL CAPITAL - MGMT and previous mayor's covariates
set more off
use "Carreri_JOP_Cross.dta", clear
cap erase "TableA26_PanelA.txt"
cap erase "TableA26_PanelA.tex"
cap erase "TableA26_PanelB.txt"
cap erase "TableA26_PanelB.tex"
duplicates drop municipality_id, force
keep if low_social_capital==1
* Panel A
reg ageold mgmt
outreg2 using "TableA26_PanelA.tex", tex(land) bdec(3) nocon label	
reg job_highold mgmt
outreg2 using "TableA26_PanelA.tex", tex(land) bdec(3) nocon label	
reg job_lowold mgmt
outreg2 using "TableA26_PanelA.tex", tex(land) bdec(3) nocon label	
reg job_unemployedold mgmt
outreg2 using "TableA26_PanelA.tex", tex(land) bdec(3) nocon label	
reg educ_less_13old mgmt
outreg2 using "TableA26_PanelA.tex", tex(land) bdec(3) nocon label	
reg educ_13old mgmt
outreg2 using "TableA26_PanelA.tex", tex(land) bdec(3) nocon label	
reg educ_14_18old mgmt
outreg2 using "TableA26_PanelA.tex", tex(land) bdec(3) nocon label	
* Panel B
reg ageold age
outreg2 using "TableA26_PanelB.tex", tex(land) bdec(3) nocon label	
reg job_highold job_high
outreg2 using "TableA26_PanelB.tex", tex(land) bdec(3) nocon label	
reg job_lowold job_low
outreg2 using "TableA26_PanelB.tex", tex(land) bdec(3) nocon label	
reg job_unemployedold job_unemployed
outreg2 using "TableA26_PanelB.tex", tex(land) bdec(3) nocon label	
reg educ_less_13old educ_less_13
outreg2 using "TableA26_PanelB.tex", tex(land) bdec(3) nocon label	
reg educ_13old educ_13
outreg2 using "TableA26_PanelB.tex", tex(land) bdec(3) nocon label	
reg educ_14_18old educ_14_18
outreg2 using "TableA26_PanelB.tex", tex(land) bdec(3) nocon label	
erase "TableA26_PanelA.txt"
erase "TableA26_PanelB.txt"




*** T A27 - SOCIAL CAPITAL - Components of Surplus (in low social capital)
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "TableA27.txt"
cap erase "TableA27.tex"
keep if year_normalized>=-4 & year_normalized<=4 & low_social_capital==1
foreach y in expenditure_tot ///
			 expenditure_current expenditure_capital expenditure_other  ///
			 revenue_tot ///
			 revenue_tax revenue_transfer revenue_other {
reghdfe `y'_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
 	su `y'_w if e(sample)==1 & post==0
	local m`y'_w = r(mean)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
outreg2 using "TableA27.tex", tex(land)   ///
		keep(post_mgmt)  /// 
		addstat(Municipalities, `num_mun', Mean Outcome Pre, `m`y'_w', Standardized Effect, `standard') ///
		bdec(3) nocon label			
}
erase "TableA27.txt"




*** T A28 - SOCIAL CAPITAL - Service Quality
set more off
use "Carreri_JOP_Panel.dta", clear
cap erase "TableA28.txt"
cap erase "TableA28.tex"
* 1) Low Social Capital
 reghdfe sose_rank post_mgmt post if low_social_capital==1, ///
  absorb(municipality_id year_normalized i.post#c.pia) ///
  vce(cluster municipality_id)  keepsingletons 
 	su sose_rank if e(sample)==1 & post==0
	local msose_rank=r(mean)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
 outreg2 using "TableA28.tex", tex   ///
		addstat(Municipalities, `num_mun', Mean Outcome Pre, `msose_rank', Standardized Effect, `standard') ///
 		keep(post_mgmt) addtext(Sample, Low Social Capital)  /// 
 	    bdec(3) nocon label
* 2) High Social Capital
 reghdfe sose_rank post_mgmt post if low_social_capital==0, ///
  absorb(municipality_id year_normalized i.post#c.pia) ///
  vce(cluster municipality_id)  keepsingletons 
 	su sose_rank if e(sample)==1 & post==0
	local msose_rank=r(mean)
	egen num_mun=nvals(municipality_id) if e(sample)==1
	su num_mun
	local num_mun=r(mean)
	drop num_mun
	su mgmt if e(sample)==1
	local standard =r(sd)*_b[post_mgmt]
 outreg2 using "TableA28.tex", tex   ///
		addstat(Municipalities, `num_mun', Mean Outcome Pre, `msose_rank', Standardized Effect, `standard') ///
 		keep(post_mgmt) addtext(Sample, High Social Capital)  /// 
 	    bdec(3) nocon label
erase "TableA28.txt"





**************************************************
*                 MAIN FIGURES                   *
**************************************************
graph set window fontface "Times New Roman"

*** F1 - Distribution of surplus
set more off
use "Carreri_JOP_Panel.dta", clear
hist surplus, ///
	width(.025) ///
	xtitle("Surplus") xlabel(-.75(.25).75) ///
    ytitle("Density") ylabel(, angle(0) nogrid ) ///
    legend(off) color(gray) lcolor(white) ///
    graphregion(color(white)) plotregion(color(white)) ///
	addplot(pci 0  0  4.1  0, lcolor(red) lwidth(thick))
graph export "Figure1.pdf", as(pdf) replace



*** F2 - Distribution of MGMT Score
set more off
use "Carreri_JOP_Cross.dta", clear
* Full Sample
preserve
duplicates drop municipality_id, force
su mgmt 
hist mgmt, ///
    width(.2) ///
    title("Panel A: Full Sample", color(black) size(medlarge)) ///
	xtitle("Competence Score", size(medium)) xlabel(1(1)5, labsize(medsmall)) ///
    ytitle("Density", size(medium)) ylabel(0(.2)1, labsize(medium) angle(0) nogrid ) ///
    legend(off) color(gray) lcolor(white) ///
    graphregion(color(white)) plotregion(color(white)) ///
	addplot(pci 0  2.994674  .85  2.994674, lcolor(red) lwidth(thick))
	graph save "Figure2_full", replace
* South
replace area= proper(area)
su mgmt if area=="South"
hist mgmt if area=="South", ///
    width(.2) ///
	title("Panel B: South", color(black) size(medlarge)) ///
	xtitle("Competence Score", size(medium)) xlabel(1(1)5, labsize(medsmall)) ///
    ytitle("Density", size(medium)) ylabel(0(.2)1, labsize(medium) angle(0) nogrid ) ///
    legend(off) color(gray) lcolor(white) ///
    graphregion(color(white)) plotregion(color(white)) ///
	addplot(pci 0    2.917763  .85    2.917763, lcolor(red) lwidth(thick))
	graph save "Figure2_south", replace
* North
su mgmt if area=="North"
hist mgmt if area=="North", ///
    width(.2) ///
	title("Panel C: North", color(black) size(medlarge)) ///
	xtitle("Competence Score", size(medium)) xlabel(1(1)5, labsize(medsmall)) ///
    ytitle("Density", size(medium)) ylabel(0(.2)1, labsize(medsmall) angle(0) nogrid ) ///
    legend(off) color(gray) lcolor(white) ///
    graphregion(color(white)) plotregion(color(white)) ///
	addplot(pci 0  2.986836  .85  2.986836, lcolor(red) lwidth(thick))
	graph save "Figure2_north", replace
* Centre
su mgmt if area=="Centre"
hist mgmt if area=="Centre", ///
    width(.2) ///
	title("Panel D: Center", color(black) size(medlarge)) ///
	xtitle("Competence Score", size(medium)) xlabel(1(1)5, labsize(medsmall)) ///
    ytitle("Density", size(medium)) ylabel(0(.2)1, labsize(medsmall) angle(0) nogrid ) ///
    legend(off) color(gray) lcolor(white) ///
    graphregion(color(white)) plotregion(color(white)) ///
	addplot(pci 0  3.137255  .85  3.137255, lcolor(red) lwidth(thick))
	graph save "Figure2_centre", replace
restore
graph combine "Figure2_full" "Figure2_south" "Figure2_north" "Figure2_centre" , graphregion(color(white))
graph export "Figure2.pdf", as(pdf) replace
erase "Figure2_full.gph" 
erase "Figure2_south.gph" 
erase "Figure2_north.gph"  
erase "Figure2_centre.gph"




*** F3 - Surplus Diff-in-Diff Graph
set more off
use "Carreri_JOP_Panel.dta", clear
forvalues i=1(1)9 {
 gen d`i'=mgmt*period_`i'
 }
 keep if year_normalized>=-4 & year_normalized<=4 & area=="south"
 reghdfe surplus_w d1-d4 d6-d9, ///
  absorb(municipality_id year_normalized i.year i.year_normalized#c.pia ///
  i.year_normalized#i.region_id ///
  i.year_normalized#c.female i.year_normalized#c.age i.year_normalized#c.job_high ///
  i.year_normalized#c.job_low i.year_normalized#c.educ_13 ///
  i.year_normalized#c.educ_14_18 i.year_normalized#c.exp_total ///
  i.year_normalized#i.party_id)
	su mgmt if e(sample)
	local mgmt_sd = r(sd)
    * save coefficients
    foreach i in 1 2 3 4 6 7 8 9 {
        local b`i' = _b[d`i']*`mgmt_sd'
        local se`i' = _se[d`i']
        local ub_b`i' = _b[d`i']*`mgmt_sd' + 1.96*_se[d`i']*`mgmt_sd'
        local lb_b`i' = _b[d`i']*`mgmt_sd' - 1.96*_se[d`i']*`mgmt_sd'
         }
  clear
  set obs 9
  egen t = seq()
  gen b = 0
  gen se = 0
  gen ub_b = 0
  gen lb_b = 0
  foreach i in 1 2 3 4 6 7 8 9 {
       replace b = `b`i'' in `i'
       replace se = `se`i'' in `i'
       replace ub_b = `ub_b`i'' in `i'
       replace lb_b = `lb_b`i'' in `i'
       }
	replace t=t-5
 twoway (connected b t, mcolor(black) lcolor(black) lpattern(solid)  msymbol(D) lwidth(medthick)) ///
		(connected lb_b t, lcolor(black) msymbol(none) lpattern(dot) lwidth(medthick)) ///
		(connected ub_b t, lcolor(black) msymbol(none) lpattern(dot) lwidth(medthick)), ///
         xtitle("Years since mayor elected") xlabel(-4(1)4, labsize(small)) ///
		 ytitle("γ estimates × standard deviation") ylabel(-0.1(0.02)0.05, nogrid angle(0) glcolor(gs16)) ///
         graphregion(color(white)) plotregion(color(white)) ///
		 legend(off) yline(0, lcolor(red) lw(medium))  ///
		 xline(0, lpattern(dot) lcolor(red) lwidth(medthick)) aspectratio(.5)
  graph export "Figure3.pdf", as(pdf) replace


  
  
*** F4: good mayors in South take mun closer to service quality in North
set more off
use "Carreri_JOP_Panel.dta", clear
replace year_normalized = year_normalized+2
* North
su sose_rank if area=="north" & post==0
binscatter sose_rank post_mgmt if area=="north" & post==1, ///
		   yline(7.049057, lcolor(red)) n(5) line(connect) ///
		   xtitle("Competence Score", size(medlarge)) xlabel(1(1)5, labsize(medium)) ///
		   ytitle("Quality of Service Provision", size(medlarge)) ylabel(4(1)7.5, labsize(medium) angle(0) nogrid ) ///
		   yscale(titlegap(*-8)) ///
		   title("Panel A: North", color(black) size(large)) ///
		   legend(off) color(black) lcolor(black) ///
		   graphregion(color(white)) plotregion(color(white)) 
graph save "Figure4_north", replace
* South
su sose_rank if area=="south" & post==0
binscatter sose_rank post_mgmt if area=="south" & post==1, ///
		   yline(4.832  , lcolor(red) lwidth(medthick)) n(5) line(connect) ///
		   xtitle("Competence Score", size(medlarge)) xlabel(1(1)5, labsize(medium)) ///
		   ytitle("Quality of Service Provision", size(medlarge)) ylabel(4(1)7.5, labsize(medium) angle(0) nogrid ) ///
		   yscale(titlegap(*-8)) ///
		   title("Panel B: South", color(black) size(large)) ///
		   legend(off) color(black) lcolor(black) ///
		   graphregion(color(white)) plotregion(color(white)) 
graph save "Figure4_south", replace
* Combine
graph combine "Figure4_north" "Figure4_south", graphregion(color(white))
graph export "Figure4.pdf", as(pdf) replace
erase "Figure4_north.gph"
erase "Figure4_south.gph"





**************************************************
*               APPENDIX FIGURES                 *
**************************************************		


*** FA1 - Reliability of Competence Score
use "Carreri_JOP_Cross", clear
duplicates drop municipality_id, force
* Panel A
twoway scatter mgmt_alt mgmt , ///
		scheme(s1color)  mcolor(black) lcolor(red) ///
		xtitle("Competence Score Interviewer 1", size(medium)) ///
		ytitle("Competence Score Interviewer 2", size(medium)) ///
		ylabel(1(1)5) xlabel(1(1)5) ///
		yscale(titlegap(*+5)) ///
		title(A: Inter-rater Reliability) ///
		aspectratio(1) ///
		||  lfit mgmt_alt mgmt, legend(off)
		graph save "FigureA1_PanelA", replace
* Panel B		
twoway scatter mgmt_error mgmt  , ///
		scheme(s1color)  mcolor(black) lcolor(red) ///
		xtitle("Competence Score Interviewer 1", size(medium)) ///
		ytitle("Measurememnt Error", size(medium)) ///
		ylabel(0(.5)1.5) xlabel(1(1)5) ///
		yscale(titlegap(*+5)) ///
		title(B: Measurement Error and Competence) ///
		aspectratio(1) ///
		||  lfit mgmt_error mgmt, legend(off)
		graph save "FigureA1_PanelB", replace
		
graph combine "FigureA1_PanelA" "FigureA1_PanelB", graphregion(color(white))
graph export "FigureA1.pdf", as(pdf) replace
pwcorr mgmt_alt mgmt, sig
erase "FigureA1_PanelA.gph"
erase "FigureA1_PanelB.gph"




*** FA2 - Outliers: drop one muni at a time from Surplus D-i-D
set more off
use "Carreri_JOP_Panel", clear
cap erase "output.dta"
keep if area=="south"
reghdfe surplus_w post_mgmt, ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
 keep if e(sample)==1
 egen newid=group(municipality_id)
 codebook municipality_id
tempname results
postfile `results' coef uci lci using "output"
forvalues x=1(1)73{
reghdfe surplus_w post_mgmt if newid!=`x', ///
 absorb(municipality_id year year_normalized i.post#i.region_id i.post#c.pia ///
 i.post#c.female i.post#c.age i.post#c.job_high ///
 i.post#c.job_low i.post#c.educ_13 ///
 i.post#c.educ_14_18 i.post#c.exp_total ///
 i.post#i.party_id) ///
 vce(cluster municipality_id)  keepsingletons 
post `results' (_b[post_mgmt]) (_b[post_mgmt]+1.96*_se[post_mgmt]) (_b[post_mgmt]-1.96*_se[post_mgmt])
}
postclose `results'
use "output", clear
gen n=_n
 twoway (rcap lci uci n, lcolor(gs10) msymbol(none) lwidth(medthin)) ///
		(scatter coef n , mcolor(black) lcolor(black)  msymbol(o)) , ///
		 xtitle("Municipality (in South) dropped") xlabel(1(2)73, labsize(vsmall)) ///
		 ytitle("γ estimates") ylabel(-0.06(0.01)0.01, nogrid angle(0) glcolor(gs16)) ///
		 yscale(titlegap(*-20)) ///
		 xscale(titlegap(*+8)) ///
         graphregion(color(white)) plotregion(color(white)) ///
		 legend(off) yline(0, lcolor(red) lw(medium))  ///
		 aspectratio(.5)
graph export "FigureA2.pdf", as(pdf) replace
erase "output.dta"


*** FA3 - Outliers: drop one muni at a time from Services Did
set more off
use "Carreri_JOP_Panel", clear
cap erase "output.dta"
keep if area=="south"
reghdfe sose_rank post_mgmt post , ///
  absorb(municipality_id year_normalized i.post#c.pia) ///
  vce(cluster municipality_id)  keepsingletons 
 keep if e(sample)==1
 egen newid=group(municipality_id)
tempname results
postfile `results' coef uci lci using "output"
forvalues x=1(1)25{
reghdfe sose_rank post_mgmt post if newid!=`x' , ///
  absorb(municipality_id year_normalized i.post#c.pia) ///
  vce(cluster municipality_id)  keepsingletons 
post `results' (_b[post_mgmt]) (_b[post_mgmt]+1.96*_se[post_mgmt]) (_b[post_mgmt]-1.96*_se[post_mgmt])

}
postclose `results'
use "output", clear
gen n=_n
 twoway (rcap lci uci n, lcolor(gs10) lwidth(medium) msymbol(none)) ///
		(scatter coef n , mcolor(black) msymbol(D)), ///
         xtitle("Municipality (in South) dropped") xlabel(1(1)25, labsize(small)) ///
		 ytitle("γ estimates") ylabel(-0.5(0.5)2, nogrid angle(0) glcolor(gs16)) ///
		 xscale(titlegap(*+5)) ///
         graphregion(color(white)) plotregion(color(white)) ///
		 legend(off) yline(0, lcolor(red) lw(medium))  ///
		  aspectratio(.5)
graph export "FigureA3.pdf", as(pdf) replace
erase "output.dta"




*** FA4- SOCIAL CAPITAL - Surplus Diff-in-Diff Graph
set more off
use "Carreri_JOP_Panel", clear
forvalues i=1(1)9 {
 gen d`i'=mgmt*period_`i'
 }
 keep if year_normalized>=-4 & year_normalized<=4 & low_social_capital==1
 reghdfe surplus_w d1-d4 d6-d9, ///
  absorb(municipality_id year_normalized i.year i.year_normalized#c.pia ///
  i.year_normalized#i.region_id ///
  i.year_normalized#c.female i.year_normalized#c.age i.year_normalized#c.job_high ///
  i.year_normalized#c.job_low i.year_normalized#c.educ_13 ///
  i.year_normalized#c.educ_14_18 i.year_normalized#c.exp_total ///
  i.year_normalized#i.party_id)
	su mgmt if e(sample)
	local mgmt_sd = r(sd)
    * save coefficients
    foreach i in 1 2 3 4 6 7 8 9 {
        local b`i' = _b[d`i']*`mgmt_sd'
        local se`i' = _se[d`i']
        local ub_b`i' = _b[d`i']*`mgmt_sd' + 1.96*_se[d`i']*`mgmt_sd'
        local lb_b`i' = _b[d`i']*`mgmt_sd' - 1.96*_se[d`i']*`mgmt_sd'
         }
  clear
  set obs 9
  egen t = seq()
  gen b = 0
  gen se = 0
  gen ub_b = 0
  gen lb_b = 0
  foreach i in 1 2 3 4 6 7 8 9 {
       replace b = `b`i'' in `i'
       replace se = `se`i'' in `i'
       replace ub_b = `ub_b`i'' in `i'
       replace lb_b = `lb_b`i'' in `i'
       }
	replace t=t-5
 twoway (connected b t, mcolor(black) lcolor(black) lpattern(solid)  msymbol(D) lwidth(medthick)) ///
		(connected lb_b t, lcolor(black) msymbol(none) lpattern(dot) lwidth(medthick)) ///
		(connected ub_b t, lcolor(black) msymbol(none) lpattern(dot) lwidth(medthick)), ///
         xtitle("Years since mayor elected") xlabel(-4(1)4, labsize(small)) ///
		 ytitle("γ estimates × standard deviation") ylabel(-0.1(0.02)0.05, nogrid angle(0) glcolor(gs16)) ///
		 yscale(titlegap(*-20)) ///
         graphregion(color(white)) plotregion(color(white)) ///
		 legend(off) yline(0, lcolor(red) lw(medium))  ///
		 xline(0, lpattern(dot) lcolor(red) lwidth(medthick)) aspectratio(.5)
  graph export "FigureA4.pdf", as(pdf) replace
  
  
  
  

*** FA5- SOCIAL CAPITAL - good mayors in South take mun closer to service quality in North
set more off
use "Carreri_JOP_Panel", clear
replace year_normalized = year_normalized+2
* North
su sose_rank if low_social_capital==0 & post==0
binscatter sose_rank post_mgmt if low_social_capital==0 & post==1, ///
		   yline(6.38, lcolor(red)) n(5) line(connect) ///
		   xtitle("Competence Score", size(medlarge)) xlabel(1(1)5, labsize(medium)) ///
		   ytitle("Quality of Service Provision", size(medlarge)) ylabel(4(1)7.5, labsize(medium) angle(0) nogrid ) ///
		   title("Panel A: High Social Capital", color(black) size(large)) ///
		   legend(off) color(black) lcolor(black) ///
		   graphregion(color(white)) plotregion(color(white)) 
graph save "FigureA5_PanelA", replace
* South
su sose_rank if low_social_capital==1 & post==0
binscatter sose_rank post_mgmt if low_social_capital==1 & post==1, ///
		   yline(5.6  , lcolor(red) lwidth(medthick)) n(5) line(connect) ///
		   xtitle("Competence Score", size(medlarge)) xlabel(1(1)5, labsize(medium)) ///
		   ytitle("Quality of Service Provision", size(medlarge)) ylabel(4(1)7.5, labsize(medium) angle(0) nogrid ) ///
		   title("Panel B: Low Social Capital", color(black) size(large)) ///
		   legend(off) color(black) lcolor(black) ///
		   graphregion(color(white)) plotregion(color(white)) 
graph save "FigureA5_PanelB", replace
* Combine
graph combine "FigureA5_PanelA" "FigureA5_PanelB", graphregion(color(white))
graph export "FigureA5.pdf", as(pdf) replace
erase "FigureA5_PanelA.gph"
erase "FigureA5_PanelB.gph"






